package cn.fy.erupt.model.work;

import javax.persistence.*;

import org.hibernate.annotations.SQLDelete;

import xyz.erupt.annotation.*;
import xyz.erupt.annotation.sub_erupt.*;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.*;
import xyz.erupt.upms.handler.DictCodeChoiceFetchHandler;
import xyz.erupt.upms.helper.HyperModelVo;
import xyz.erupt.upms.model.EruptUser;
import xyz.erupt.upms.model.base.HyperModel;
import xyz.erupt.jpa.model.BaseModel;
import java.util.Set;
import java.util.Date;

@Erupt(
		name = "排班表",
		filter = @Filter("deleted = false"),
		power = @Power(importable = true, export = true)
)
@Table(name = "t_work_scheduling")
@SQLDelete(sql="update t_work_scheduling set deleted = true, deleteTime = now() where id = ?")
@Entity
public class Scheduling extends HyperModelVo {

        @EruptField(
                views = @View(
                        title = "日期", sortable = true
                ),
                edit = @Edit(
                        title = "日期",
                        type = EditType.DATE, search = @Search(vague = true), notNull = true,
                        dateType = @DateType,
	                    placeHolder = "请选择日期"
                )
        )
        private Date date;

        @EruptField(
                views = @View(
                        title = "人员",
                        column = "name"
                ),
                edit = @Edit(
                        title = "人员",
                        type = EditType.REFERENCE_TREE, search = @Search, notNull = true,
                        filter = @Filter("EruptUser.isAdmin = false"),
                        referenceTreeType = @ReferenceTreeType(id = "id", label = "name"),
                        placeHolder = "请选择人员"
                )
        )
        @ManyToOne
        private EruptUser user;

        @EruptField(
                views = @View(
                        title = "班次"
                ),
                edit = @Edit(
                        title = "班次",
                        type = EditType.CHOICE, search = @Search, notNull = true,
                		choiceType = @ChoiceType(
                				fetchHandler = DictCodeChoiceFetchHandler.class,
            	            //参数一必填，需替换成实际的字典编码
            	            //参数二可不填，表示缓存时间，默认为3000毫秒
            	            fetchHandlerParams = {"TimeType"}
                	    ),
                        placeHolder = "请选择班次"
                )
        )
        private String timeType;
        
        //逻辑删除
        private Boolean deleted = false;

}
